package com.zl.learning.thread.thread_daemon;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class TestCallable {
    public static void main(String[] args) {
        FutureTask<Integer> futureTask = new FutureTask<>(() -> {
            int i = 0;
            for (; i < 100; i++) {
                System.out.println(Thread.currentThread().getName() + ":" + i);
            }
            return i;
        });
        FutureTask<Integer> futureTask2 = new FutureTask<>(() -> {
            int i = 0;
            for (; i < 100; i++) {
                System.out.println(Thread.currentThread().getName() + ":" + i);
                if (i == 20) return i;
            }
            return i;
        });
        Thread t = new Thread(futureTask);
        Thread t2 = new Thread(futureTask2);
        t.start();
        t2.start();

        try {
            t.join();
            t2.join();
            int i = futureTask.get();
            int j = futureTask2.get();
            System.out.println(i+j);
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        }
    }
}
